package com.gisocn.onemap.base;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import com.gisocn.onemap.base.BasePresenter;

/* loaded from: classes.dex */
public abstract class BaseFragment<P extends BasePresenter> extends Fragment {
    private boolean isUIVisible;
    private boolean isViewCreated;
    protected P presenter;
    public ProgressDialog progressDialog;

    protected abstract P createPresenter();

    protected abstract void initData();

    protected abstract void onInvisible();

    @Override // androidx.fragment.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.presenter = createPresenter();
        return super.onCreateView(layoutInflater, viewGroup, bundle);
    }

    @Override // androidx.fragment.app.Fragment
    public void onViewCreated(View view, Bundle bundle) {
        super.onViewCreated(view, bundle);
        this.isViewCreated = true;
        lazyLoad();
    }

    @Override // androidx.fragment.app.Fragment
    public void setUserVisibleHint(boolean z) {
        super.setUserVisibleHint(z);
        if (z) {
            this.isUIVisible = true;
            lazyLoad();
            return;
        }
        this.isUIVisible = false;
        onInvisible();
    }

    private void lazyLoad() {
        if (this.isViewCreated && this.isUIVisible) {
            initData();
            this.isViewCreated = false;
            this.isUIVisible = false;
        }
    }

    @Override // androidx.fragment.app.Fragment
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    public void showToast(String str) {
        Toast.makeText(getActivity(), str, 0).show();
    }

    public String getStr(EditText editText) {
        return editText.getText().toString().trim();
    }

    public String getStr(TextView textView) {
        return textView.getText().toString().trim();
    }

    public boolean isNull(String str) {
        return str == null || "".equals(str) || "null".equalsIgnoreCase(str);
    }

    public boolean isNull(EditText editText) {
        return editText.getText().toString() == null || "".equals(editText.getText().toString().trim()) || "null".equalsIgnoreCase(editText.getText().toString().trim());
    }

    public void showLoading() {
        showProgressDialog();
    }

    public void hideLoading() {
        dismissProgressDialog();
    }

    public ProgressDialog showProgressDialog() {
        ProgressDialog progressDialog = new ProgressDialog(getActivity());
        this.progressDialog = progressDialog;
        progressDialog.setMessage("数据加载中...");
        this.progressDialog.show();
        this.progressDialog.setCanceledOnTouchOutside(false);
        return this.progressDialog;
    }

    public ProgressDialog showProgressDialog(CharSequence charSequence) {
        ProgressDialog progressDialog = new ProgressDialog(getActivity());
        this.progressDialog = progressDialog;
        progressDialog.setMessage(charSequence);
        this.progressDialog.show();
        return this.progressDialog;
    }

    public void dismissProgressDialog() {
        ProgressDialog progressDialog = this.progressDialog;
        if (progressDialog == null || !progressDialog.isShowing()) {
            return;
        }
        this.progressDialog.dismiss();
    }

    @Override // androidx.fragment.app.Fragment
    public void onDestroyView() {
        super.onDestroyView();
        P p = this.presenter;
        if (p != null) {
            p.detachView();
        }
        Log.e("onDestroyView", "onDestroyView");
    }
}
